<?php

namespace app\common\model;

use think\Db;
use think\Model;


class RewardRecord extends Model
{

    

    

    // 表名
    protected $name = 'reward_record';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];
	
    public function user() {
    	return $this->belongsTo('user', 'user_id', 'id', '', 'left')->setEagerlyType(0);
    }
	
	
	public function agent() {
		return $this->belongsTo('agentShop', 'agent_id', 'id', '', 'left')->setEagerlyType(0);
	}
	
	/**
	 * 添加奖励记录
	 * @param $userId 用户ID
	 * @param $number 数量
	 * @param String $remark  备注
	 * @param String $agentId 关联代理
	 * @return int|string
	 */
	public static function addRecord($userId, $number, $remark = '', $agentId = '') {
		return Db::name('rewardRecord')
			->insert([
				'user_id' => $userId,
				'number' => $number,
				'remark' => $remark,
				'agent_id' => $agentId,
				'create_time' => time(),
				'update_time' => time()
			]);
	}





}
